package scheduler;

import java.util.ArrayList;


public class BillingSite {
	String billingSiteRef;
	SiteType siteType;
	String scriptName;
	int concurrentScrapes;
	ArrayList<MaintWindow> maintenanceWindows;
	int retryInterval; // Days
	int billingCycle; // Days
	int leadTime;	// Days
	String[] idFields = new String[5];
	String[] authFields = new String[5];

	//RequestParameter requiredFields[] = new RequestParameter[10];

	public BillingSite(String billingRef, String script, int billingCycle,
			int interval, int leadTime, int concurrent)
	{
		setBillingSiteRef(billingRef);
		setScriptName(script);
		//setMaintenanceWindow();
		setBillingCycle(billingCycle);
		setRetryInterval(interval);
		setLeadTime(leadTime);
		setConcurrentScrapes(concurrent);
		//setIDFields();
		//setAuthFields();
	}


	public BillingSite() {
		super();
		// TODO Auto-generated constructor stub
	}


	public static BillingSite buildBillingSite(int x) {
		BillingSite billingSite = new BillingSite();
		switch (x) {
		case 1:
			billingSite.billingSiteRef = "Johannesburg Municipality";
			billingSite.siteType = SiteType.MUNICIPALITY;
			billingSite.scriptName = "Johannesburg_Municipality_Script";
			billingSite.retryInterval = 7; // Set interval to once a week
			billingSite.scriptName = "Municpality";
			billingSite.concurrentScrapes = 2;
			billingSite.billingCycle = 30; // once a month
			billingSite.leadTime = 5; // Start trying 5 days before due date
			//billingSite.requiredFields = new RequestParameter[10]; 

			// Add the Parameters for this site
			billingSite.idFields[0] = "UserName"; 
			billingSite.idFields[1] = "SystemName"; 
			billingSite.idFields[2] = "AccountNumber";
			billingSite.idFields[3] = "EmailAddress";
			billingSite.idFields[4] = "TelephoneNumber";;

			billingSite.authFields[0] = "UserId";
			billingSite.authFields[1] = "Password";
			billingSite.authFields[2] = "IdNumber";
			billingSite.authFields[3] = "PinNumber";
			billingSite.authFields[4] = "SecurityCode";
			break;
		case 2:
			billingSite.billingSiteRef = "Telkom";
			billingSite.siteType = SiteType.TELKOM;
			billingSite.scriptName = "Telkom_Script";
			billingSite.retryInterval = 1; // Set interval to daily
			billingSite.concurrentScrapes = 6;
			billingSite.billingCycle = 30; // once a month
			billingSite.leadTime = 1; // Start trying 1 day before due date

			// Add the Parameters for this site
			billingSite.idFields[0] = "UserName"; 
			billingSite.idFields[1] = "SystemName"; 
			billingSite.idFields[2] = "AccountNumber";

			billingSite.authFields[0] = "IdNumber";
			billingSite.authFields[1] = "Password";
			billingSite.authFields[4] = "SecurityCode";

			break;
		case 3:
			billingSite.billingSiteRef = "American Express";
			billingSite.siteType = SiteType.CREDITCARD;
			billingSite.scriptName = "American_Express_Script";
			billingSite.retryInterval = 1; // Set interval to daily
			billingSite.concurrentScrapes = 3;
			billingSite.billingCycle = 30; // once a month
			billingSite.leadTime = 7; // Start trying 7 days before due date

			// Add the Parameters for this site
			billingSite.idFields[0] = "UserName"; 
			billingSite.idFields[1] = "EmailAddress";
			billingSite.idFields[2] = "TelephoneNumber";;

			billingSite.authFields[0] = "UserId";
			billingSite.authFields[2] = "Password";
			billingSite.authFields[3] = "SecurityCode";
			break;
		}
		return billingSite;
	}


	public BillingSite buildBillingSite(String billingSiteRef) {
		BillingSite billingSiteByRef = null;

		if (billingSiteRef == "Johannesburg Municipality")
			billingSiteByRef = buildBillingSite(1);
		else if (billingSiteRef == "Telkom")
			billingSiteByRef = buildBillingSite(2);
		else if (billingSiteRef == "American Express")
			billingSiteByRef = buildBillingSite(3);

		return billingSiteByRef;
	}

	public String getBillingSiteRef() {
		return billingSiteRef;
	}

	public void setBillingSiteRef(String billingSiteRef) {
		this.billingSiteRef = billingSiteRef;
	}

	public SiteType getSiteType() {
		return siteType;
	}

	public void setSiteType(SiteType siteType) {
		this.siteType = siteType;
	}

	public String getScriptName() {
		return scriptName;
	}

	public void setScriptName(String scriptName) {
		this.scriptName = scriptName;
	}

	public int getConcurrentScrapes() {
		return concurrentScrapes;
	}

	public void setConcurrentScrapes(int concurrentScrapes) {
		this.concurrentScrapes = concurrentScrapes;
	}

	public ArrayList<MaintWindow> getMaintenanceWindows() {
		return maintenanceWindows;
	}

	public void setMaintenanceWindows(ArrayList<MaintWindow> maintenanceWindows) {
		this.maintenanceWindows = maintenanceWindows;
	}

	public int getRetryInterval() {
		return retryInterval;
	}

	public void setRetryInterval(int retryInterval) {
		this.retryInterval = retryInterval;
	}

	public int getBillingCycle() {
		return billingCycle;
	}

	public void setBillingCycle(int billingCycle) {
		this.billingCycle = billingCycle;
	}

	public int getLeadTime() {
		return leadTime;
	}

	public void setLeadTime(int leadTime) {
		this.leadTime = leadTime;
	}

	public void print() {
		System.out.println( "Billing Site");
		System.out.println("\tbillingSiteRef:    " + this.billingSiteRef);
		System.out.println("\tscriptName:        " + this.scriptName);
		System.out.println("\tsiteType:          " + this.siteType );
		System.out.println("\tconcurrentScrapes: " + this.concurrentScrapes);
		System.out.println("\tbillingCycle:      " + this.billingCycle);
		System.out.println("\tretryInterval:     " + this.retryInterval);
		System.out.println("\tleadTime:          " + this.leadTime);
		for (int i=0;i<5;i++) {
			System.out.println("\t\tId Field["+ i + "]    :" + this.idFields[i]);
			System.out.println("\t\tAuth Field["+ i + "]  :" + this.authFields[i]);
		}


	}
}